package solution

import (
	"strings"
)

var (
	roman = map[string]int{
		"I":  1,
		"V":  5,
		"X":  10,
		"L":  50,
		"C":  100,
		"D":  500,
		"M":  1000,
		"IV": 4,
		"IX": 9,
		"XL": 40,
		"XC": 90,
		"CD": 400,
		"CM": 900,
	}
)

func V1(s string) int {
	rst := 0

	i := 0

	str := strings.Split(s, "")

	for i < len(str) {
		if i+1 < len(str) {
			if v, ok := roman[str[i]+str[i+1]]; ok {
				rst += v
				i += 2
				continue
			}
		}

		rst += roman[str[i]]

		i += 1
	}

	return rst
}
